package com.csw.mario;

import java.awt.image.BufferedImage;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2022/11/7 18:00
 */
public class Obstacle implements Runnable {

    //坐标
    private int x;
    private int y;
    //用于记录障碍物类型
    private int type;
    //用于显示图像
    private BufferedImage show = null;
    //定义当前的场景对象
    private BackGround bg = null;
    //定义一个线程对象实现旗子下落过程
    private Thread thread = new Thread(this);

    public Obstacle(int x, int y, int type, BackGround bg) {
        this.x = x;
        this.y = y;
        this.type = type;
        this.bg = bg;
        show = StaticValue.obstacle.get(type);
        //判断是否是旗子,启动线程
        if (type == 8) {
            thread.start();
        }
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public BufferedImage getShow() {
        return show;
    }

    public void setShow(BufferedImage show) {
        this.show = show;
    }

    @Override
    public void run() {
        while (true) {
            //到达旗子
            if (this.bg.isReach()) {
                //还未落地
                if (this.y < 374) {
                    this.y += 5;
                } else {
                    this.bg.setBase(true);
                }
            }

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
